const { func } = require("joi")

let facList = [{
    facName: '设备1',
    facCode: '123451',
    status: '0',
    repairBill: '12345',
    maintainDate: '2012-12-31',
    deviceNumber: '6666666',
    initiator: '张三',
    company: 'XXX有限公司',
    model: '123',
    deviceType: 'A',
    maintainRecord: [{
        maintainDate: '2020-12-30',
        deviceType: 'C',
        maintainContent: '器械检查',
        facName: '设备1',
        facCode: '123451',
        status: '0',
        repairBill: '12345',
        deviceNumber: '6666666',
        initiator: '张三',
        company: 'XXX有限公司',
        model: '123',
        operator: '李四',

    }, {
        maintainDate: '2020-12-20',
        deviceType: 'B',
        maintainContent: '机器磨损',
        facName: '设备2',
        facCode: '123451',
        status: '0',
        repairBill: '12345',
        deviceNumber: '6666666',
        initiator: '张三',
        company: 'XXX有限公司',
        model: '123',
        operator: '李四',

    }],
    img: '无',
    operator: '李四',
    mainContent: '设备损坏',
    money: '12000',
}, {
    facName: '设备2',
    facCode: '123452',
    status: '1',
    repairBill: '21111',
    maintainDate: '2021-12-31',
    deviceNumber: '111111',
    initiator: '张三1',
    deviceType: 'B',
    company: 'XXX有限公司2',
    model: '1233',
    maintainRecord: [{
        maintainDate: '2020-12-31',
        maintainContent: '2020-12-31'
    }],
    img: '无',
    operator: '李四4',
    mainContent: '设备损坏',
    money: '22000',
}, {
    facName: '设备3',
    facCode: '123453',
    status: '2',

}, {
    facName: '设备4',
    facCode: '123454',
    status: '3',

}]
let facRepairList = [{
    facName: '设备1',
    facCode: '123451',
    status: '0',
    repairBill: '12345',
    repairDate: '2012-12-31',
    deviceNumber: '6666666',
    initiator: '张三',
    company: 'XXX有限公司',
    model: '123',
    deviceType: 'A',
    maintainRecord: '2020-12-21',
    img: '无',
    operator: '李四',
    mainContent: '设备损坏',
    money: '12000',
}, {
    facName: '设备2',
    facCode: '123452',
    status: '1',
    repairBill: '21111',
    repairDate: '2021-12-31',
    deviceNumber: '111111',
    initiator: '张三1',
    deviceType: 'B',
    company: 'XXX有限公司2',
    model: '1233',
    maintainRecord: '2020-12-21',
    img: '无',
    operator: '李四4',
    mainContent: '设备损坏',
    money: '22000',
}]
let facFaultMessage = [{ errorId: 1, grade: 1, depat: 1, subdep: 2, name: '设备类型1', note: '试剂过期' },
    { errorId: 2, grade: 1, depat: 1, subdep: 3, name: '设备类型1', note: '试剂量不足' },
    { errorId: 3, grade: 1, depat: 1, subdep: 3, name: '设备类型1', note: '没有找到相应的试剂' },
    { errorId: 4, grade: 3, depat: 1, subdep: 2, name: '设备类型1', note: '试剂已用完' },
    { errorId: 5, grade: 1, depat: 1, subdep: 2, name: '设备类型1', note: '稀释液未找到或用完' },
]
const piedata2020 = [
    { value: 1040, name: '设备类型1', month: [12, 33, 46, 24, 32, 1, 22, 46, 22, 5, 7, 5] },
    { value: 235, name: '设备类型2', month: [15, 23, 26, 45, 12, 55, 12, 36, 72, 51, 73, 52] },
    { value: 510, name: '设备类型3', month: [14, 43, 36, 25, 32, 12, 22, 42, 12, 1, 6, 15] },
    { value: 3484, name: '设备类型4', month: [12, 23, 11, 24, 33, 13, 22, 36, 42, 6, 3, 35] },
    { value: 30, name: '设备类型5', month: [11, 13, 32, 21, 32, 14, 22, 56, 32, 5, 2, 25] }
]
const piedata2021 = [
    { value: 141, name: '设备类型1', month: [12, 33, 46, 24, 32, 1, 22, 46, 22, 5, 7, 5] },
    { value: 735, name: '设备类型2', month: [15, 23, 26, 45, 12, 55, 12, 36, 72, 51, 73, 52] },
    { value: 50, name: '设备类型3', month: [14, 43, 36, 25, 32, 12, 22, 42, 12, 1, 6, 15] },
    { value: 4, name: '设备类型4', month: [12, 23, 11, 24, 33, 13, 22, 36, 42, 6, 3, 35] },
    { value: 300, name: '设备类型5', month: [11, 13, 32, 21, 32, 14, 22, 56, 32, 5, 2, 25] }
]
const piedata2019 = [
    { value: 102, name: '设备类型1', month: [12, 33, 46, 24, 32, 1, 22, 46, 22, 5, 7, 5] },
    { value: 735, name: '设备类型2', month: [15, 23, 26, 45, 12, 55, 12, 36, 72, 51, 73, 52] },
    { value: 280, name: '设备类型3', month: [14, 43, 36, 25, 32, 12, 22, 42, 12, 1, 6, 15] },
    { value: 1484, name: '设备类型4', month: [12, 23, 11, 24, 33, 13, 22, 36, 42, 6, 3, 35] },
    { value: 300, name: '设备类型5', month: [11, 13, 32, 21, 32, 14, 22, 56, 32, 5, 2, 25] }
]
const linedata = [12, 33, 46, 24, 32, 1, 22, 46, 22, 5, 7, 5]
module.exports = [
    // queryFac
    {
        url: '/vue-admin-template/facility/querylist',
        type: 'post',
        response: config => {


            return {
                code: 20000,
                data: facList
            }
        }
    },
    // queryFacRepair
    {
        url: '/vue-admin-template/facility/queryRepairlist',
        type: 'post',
        response: config => {


            return {
                code: 20000,
                data: facRepairList
            }
        }
    },
    // queryFacFaultMessage
    {
        url: '/vue-admin-template/facility/queryFacFaultMessage',
        type: 'post',
        response: config => {


            return {
                code: 20000,
                data: facFaultMessage
            }
        }
    },
    // queryFacMaintainList
    {
        url: '/vue-admin-template/facility/queryMaintainList',
        type: 'post',
        response: config => {
            let facCode = config.body.facCode
            for (let i = 0; i < facList.length; i++) {
                if (facList[i].facCode == facCode) {
                    return {
                        code: 20000,
                        data: facList[i].maintainRecord
                    }
                }
            }
            return {
                code: 20000,
                data: facList[1].maintainRecord
            }
        }
    },
    //新增设备

    {
        url: '/vue-admin-template/facility/addFac',
        type: 'post',
        response: config => {
            facList.push(
                config.body
            )

            return {
                code: 20000,
                data: '新增成功'
            }
        }
    },
    //编辑设备

    {
        url: '/vue-admin-template/facility/editFac',
        type: 'post',
        response: config => {

            facList.splice(facList.length, 1,
                config.body
            )

            return {
                code: 20000,
                data: '新增成功'
            }
        }
    },
    //删除设备

    {
        url: '/vue-admin-template/facility/delFac',
        type: 'post',
        response: config => {
            let facCode = config.body.facCode
            let newarr = []

            facList.forEach(function(i) {
                if (i.facCode != facCode) {
                    newarr.push(i)
                }
            })
            facList = newarr
            return {
                code: 20000,
                data: '删除成功'
            }
        }
    },
    //删除保修记录
    {
        url: '/vue-admin-template/facility/delRepair',
        type: 'post',
        response: config => {
            let repairBill = config.body.repairBill
            let newarr = []
            facRepairList.forEach(function(i) {
                if (i.repairBill != repairBill) {
                    newarr.push(i)
                }
            })
            facRepairList = newarr
            return {
                code: 20000,
                data: '删除成功'
            }
        }
    },
    //删除故障信息
    {
        url: '/vue-admin-template/facility/delFaultMessage',
        type: 'post',
        response: config => {
            let errorId = config.body.errorId
            let newarr = []
            for (let i = 0; i < facFaultMessage.length; i++) {
                if (facFaultMessage[i].errorId != errorId) {
                    newarr.push(facFaultMessage[i])
                }

            }
            facFaultMessage = newarr
            return {
                code: 20000,
                data: '删除成功'
            }
        }
    },
    //删除保养记录
    {
        url: '/vue-admin-template/facility/delMain',
        type: 'post',
        response: config => {
            let maintainDate = config.body.maintainDate
            let facCode = config.body.facCode
            let newarr = []
            let arr = []
            for (let i = 0; i < facList.length; i++) {
                if (facList[i].facCode == facCode) {
                    arr = facList[i].maintainRecord
                    for (let j = 0; j < arr.length; j++) {
                        if (arr[j].maintainDate != maintainDate) {
                            newarr.push(arr[j])
                        }
                    }
                    facList[i].maintainRecord = newarr
                }

            }

            return {
                code: 20000,
                data: facList
            }
        }
    },
    //提交报修申请
    {
        url: '/vue-admin-template/facility/submitRepair',
        type: 'post',
        response: config => {
            facRepairList.push(config.body)

            return {
                code: 20000,
                data: '提交成功'
            }
        }
    },
    //提交保养记录
    {
        url: '/vue-admin-template/facility/submitMaintain',
        type: 'post',
        response: config => {

            let facCode = config.body.facCode
            for (let i = 0; i < facList.length; i++) {
                if (facList[i].facCode == facCode) {
                    facList[i].maintainRecord.push(config.body)
                }
            }
            return {
                code: 20000,
                data: '提交成功'
            }
        }
    },
    //编辑报修申请
    {
        url: '/vue-admin-template/facility/editRepair',
        type: 'post',
        response: config => {
            let data = config.body
            for (let i = 0; i < facRepairList.length; i++) {
                if (facRepairList[i].repairBill == data.repairBill) {
                    facRepairList[i] = data
                    facRepairList[i].status = '4'
                }
            }
            return {
                code: 20000,
                data: '审批成功'
            }
        }
    },
    // queryyearfac
    {
        url: '/vue-admin-template/facility/queryyearfac',
        type: 'post',
        response: config => {

            let year = config.body.year
            switch (year) {
                case '2020':
                    return {
                        code: 20000,
                        data: piedata2020
                    }
                    break;
                case '2021':
                    return {
                        code: 20000,
                        data: piedata2021
                    }
                    break;
                case '2019':
                    return {
                        code: 20000,
                        data: piedata2019
                    }
                    break;
            }


        }
    },

]